package com.quectel.mobile.controller.workorder;

import cn.hutool.core.lang.func.LambdaUtil;
import com.quectel.core.module.workorder.dto.WorkOrderServiceItemDto;
import com.quectel.core.module.workorder.service.WorkOrderServiceItemService;
import com.quectel.mobile.controller.BaseController;
import com.quectel.mobile.util.SessionHolder;
import com.quectel.util.common.Request;
import com.quectel.util.common.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * 在这里编写说明
 *
 * @author: rananxin
 * @email: ryan.ran@quectel.com
 * @date: 2022-10-26 11:17:00
 */
@RestController
@RequestMapping("workOrderServiceItem")
@Tag(name = "WorkOrderServiceItemController")
public class WorkOrderServiceItemController extends BaseController {

    @DubboReference
    private WorkOrderServiceItemService workOrderServiceItemService;

    @GetMapping("list")
    @Operation(summary = "服务内容列表")
    public Response<List<WorkOrderServiceItemDto>> list(
            @Parameter(description = "名称") @RequestParam(required = false) String name
    ) {
        Request request = Request.configParams(Request.parseParams(httpServletRequest));
        request.put(LambdaUtil.getFieldName(WorkOrderServiceItemDto::getVillageId), Objects.requireNonNull(SessionHolder.getLoginMobileUserSession()).getCurrentVillageId());
        List<WorkOrderServiceItemDto> list = workOrderServiceItemService.queryList(request.getParams());
        return Response.<List<WorkOrderServiceItemDto>>ok().wrap(list);
    }
}
